<template>
  <div id="newsList" v-loading="loading">
    <div>
      <div v-for="item in newsListData" :key="item.id">
        <div class="left">
          <div class="imgs" v-if="item.image_url">
            <img :src="item.image_url" alt="" />
          </div>
          <div style="flex: 1">
            <h3 class="title curr" @click="handleDetTitle(item)">
              {{ item.title }}
            </h3>
            <div style="color: #666" class="f14">
              <div style="margin: 20px 0">{{ item.source }}</div>
              <span>{{ item.update_time }}</span>
              <span style="margin: 0 10px">|</span>
              <span>{{ item.view_total }}次浏览</span>
            </div>
          </div>
        </div>
      </div>

      <div
        v-if="newsListData.length == 0"
        style="text-align: center; margin-top: 20px"
      >
        暂无数据
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const { newsListData } = defineProps({
  newsListData: {
    type: Array,
    default: () => [],
  },
});
const loading = ref(false);
const handleDetTitle = (item) => {
  const url = '/news/detail' + '?id=' + item.id;
  window.open(url, '_blank');
};
const handleTableLoading = (isShow) => {
  loading.value = isShow;
};
defineExpose({
  handleTableLoading,
});
</script>

<style lang="scss" scoped>
#newsList {
  .left {
    display: flex;
    margin: 20px 0;
  }
  .imgs {
    width: 220px;
    height: 150px;
    margin-right: 20px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .title {
    &:hover {
      color: var(--color-text);
    }
  }
}
</style>
